package com.example.schedule.views

import android.content.Context
import android.util.AttributeSet
import androidx.core.view.setMargins
import com.airbnb.epoxy.CallbackProp
import com.airbnb.epoxy.ModelProp
import com.airbnb.epoxy.ModelView
import com.airbnb.epoxy.TextProp
import com.example.schedule.databinding.BasicRowBinding
import com.example.schedule.utils.viewBinding
import com.google.android.material.card.MaterialCardView

/**
 *Create by Fanketly on 2021/10/31
 *Gitee:https://gitee.com/fanketly
 */
@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT)
class BasicRow @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : MaterialCardView(context, attrs, defStyleAttr) {
    private val binding: BasicRowBinding by viewBinding()

    init {
        radius = 16f
    }

    @ModelProp
    fun setMargin(int: Int) {
        (layoutParams as? MarginLayoutParams)?.setMargins(int)
    }

    @TextProp
    fun setTitle(title: CharSequence?) {
        binding.title.text = title
    }

    @TextProp
    fun setSubtitle(subtitle: CharSequence?) {
        binding.subtitle.text = subtitle
    }

    @CallbackProp
    fun setClickListener(clickListener: OnClickListener?) {
        setOnClickListener(clickListener)
    }
}